package main

import (
	"fmt"
	"sync"
)

var wg sync.WaitGroup

func A(send chan<- struct{}, receive <-chan struct{}) {
	defer wg.Done()
	msg := []string{"1", "2", "3"}
	count := 0
	for range receive {
		send <- struct{}{}
		if count > 2 {
			return
		}
		fmt.Println(msg[count])
		count++

	}
}

func B(send chan<- struct{}, receive <-chan struct{}) {
	defer wg.Done()
	msg := []string{"A", "B", "C"}
	count := 0
	for range receive {
		if count > 2 {
			return
		}
		fmt.Println(msg[count])
		count++
		send <- struct{}{}
	}
}

func main() {
	a, b := make(chan struct{}), make(chan struct{})
	go A(a, b)
	go B(b, a)
	wg.Add(2)
	b <- struct{}{}
	wg.Wait()
}
